#ifndef HEADER_8CF090DAE10600B2
#define HEADER_8CF090DAE10600B2

/*****************************************************************************************
 * avtype.h
 *
 *  Created on: May 16, 2013
 *      Author: meekwolf
 *****************************************************************************************/
#ifndef FS_FRAME_H_
#define FS_FRAME_H_

/***************************************************************/
#define FSFrameTag  *(U32*)"FSFM"
#define FSFrameEnd  *(U32*)"E_FM"
#define IFrame		'I'
#define PFrame      'P'
#define AFrame      'A'
#define MFrame      'M'
#define CFrame      'C' //switch file ctrl Frame

#define EncH264		'F'
#define EncMJ		'J'
#define EncPCM		'P'



#define FS_FRANE_TAG_LEN    ( sizeof(U32) )

/***************************************************************/
#define ATTRIBUTE_PACKED __attribute__((packed))
typedef struct _VideoHead_
{
    U16  VWidth;
    U16  VHeight;
    U32  VFrameRate;
    U32  VBitRate;
} ATTRIBUTE_PACKED VideoHead_t;

typedef struct AudioHead_t
{
    U32  sampleRate;
    U32  bitsPerSample;
} ATTRIBUTE_PACKED AudioHead_t;

typedef struct _FsFrame_
{
    U32 frameTag;
    U8  encrypted;
    U8  encodeType;
    U8  frameType;
    U8  channel;
    U32 frameNo;
    U32 dataLen;
    S64 pts;
    S64 time;
    union
    {
        VideoHead_t video;
        AudioHead_t audio;
    };
	U8  fillLen;
    U8  reserved[7];
    S8  data[0];
} ATTRIBUTE_PACKED FsFrame_t;


#define  IS_FRAMEEND(f)  \
    ( ( *(U32*)( (S8*)f + sizeof(FsFrame_t) + f->dataLen - FS_FRANE_TAG_LEN) ) ==  FSFrameEnd ?  1 : 0 )

#define  IS_FRAME(f)  \
    ( ( f->frameTag == FSFrameTag && ( f->frameType == IFrame || f->frameType == PFrame || f->frameType == MFrame || f->frameType == AFrame ) ) ?  1 : 0 )

#define  IS_VFRAME(f) \
    ( ( f->frameTag == FSFrameTag && ( f->frameType == IFrame || f->frameType == PFrame) ) ?  1 : 0 )

#define  IS_AFRAME(f) \
    ( ( f->frameTag == FSFrameTag && f->frameType == AFrame ) ?  1 : 0 )


#define  IS_IFRAME(f) \
    ( ( f->frameTag == FSFrameTag && f->frameType == IFrame ) ?  1 : 0 )

#define  IS_PFRAME(f) \
    ( ( f->frameTag == FSFrameTag && f->frameType == PFrame ) ?  1 : 0 )

#define  IS_MFRAME(f) \
    ( ( f->frameTag == FSFrameTag && f->frameType == MFrame ) ?  1 : 0 )



/***************************************************************/
#endif /* FS_FRAME_H_ */

#endif // header guard
